function UpdateAppList(){

		//clear nodes:
		$('#app_icon_list').empty();
		$('#app_list_overview').empty();
		var callback = function(results){
			var i = 0;
			if(results[0] != 0 && results[0] != 1){
   			
				for(;i<results.length;i++){

					var img = $('<img>').attr('src',results[i].icon);
					var figure = $('<figure>').append(img);
					var a = $('<a>').addClass('logo').append(figure);
					var btn_div = $('<div>').addClass('add_btn_div');
					var btn = $('<a>').addClass('add_btn').appendTo(btn_div).text("已添加");
					var p =$('<p>').addClass('main').text(results[i].name);

					var li = $('<li>').append(a).append(btn_div).append(p).appendTo($('#app_list_overview'));

					//for app_icon_list
					var img = $('<img>').attr({'src':results[i].icon,'draggable':'false'});
					var p =$('<p>').addClass('ellipsis').text(results[i].name);
					var img_cover = $('<span>').addClass('img_cover');
					var img_div = $('<div>').addClass('img_div').append(img_cover).append(img);

					var li = $('<li>').append(img_div).append(p).data('result',results[i]).bind('click',{'result':results[i]},function(e){
						var result = e.data['result'];
						console.log(e);
						if(result.ismax)
							window.open(result.url,result.name,'height='+result.height+',width='+result.width+',menubar=yes,scrollbars=yes, location=yes, status=yes');
						else
							window.open(result.url,result.name,'height='+result.height+',width='+result.width);
					}).hover(function(){
						$(this).find('.img_div').stop().transition({ scale: 1.1 });
						
					},function(){
						$(this).find('.img_div').stop().transition({ scale: 1.0 });
					
					}).appendTo($('#app_icon_list')).stop().transition({
										     scale: 1.2 
										}).transition({scale: 1.0 });

					

				}
			}
			//for add button
				var img = $('<img>').attr({'src':'cuc://homepage/add_app_icon.png','draggable':'false'});
				
				var img_cover = $('<span>').addClass('img_cover');
				var img_div = $('<div>').addClass('img_div').append(img_cover).append(img);
				var p =$('<p>').addClass('ellipsis').text(' ');
				var li = $('<li>').append(img_div).append(p).click(function(){

					var cover = $('<div>').addClass('COVER').appendTo('body');
					
					var title = $('<h3>').addClass('cwk_title').text('添加应用');
					var add_btn_div = $('<div>').addClass('add_btn_div');
					var btn_verify_nmi_app = $('<button>')
					.addClass('cwk_button')
					.text('添加NMI应用')
					.on('click',function(e){
						e.stopPropagation();
						window.open('cuc://homepage/verifypage.html','cwkshell','height=510,width=810,toolbar=no,status=no,menubar=no');
						//window.open('../verifypage/index.html','a','height=510,width=810');
						$('.COVER').click();
					}).appendTo(add_btn_div);
					var btn_web_app = $('<button>').addClass('cwk_button').text('添加Web应用').appendTo(add_btn_div);
					
					var card_div = $('<div>').addClass('card_div')
					.append(title)
					.append(add_btn_div)
					.appendTo(cover)
					.bind('click',function(e){

					})
					.transition({ scale: 1.1,rotateY: '180deg' },200)
					.transition({ scale: 1.0,rotateY: '0deg' },600);

					var wnd_height = $(window).height();
					var wnd_width = $(window).width();
					
					var left = (wnd_width - card_div.width())/2;
					var top = (wnd_height - card_div.height())/2;

					card_div.css({

						'top':top+'px',
						'left':left + 'px'
					});

				}).hover(function(){
					$(this).find('.img_div').stop().transition({ scale: 1.1 });
					
				},function(){
					$(this).find('.img_div').stop().transition({ scale: 1.0 });
				
				}).appendTo($('#app_icon_list')).stop().transition({
									     scale: 1.2 
									}).transition({scale: 1.0 });
		};


		var db = new AppListDB();
		db.getAllApps(callback);
	}


$(document).ready(function(){

	$("#homepage_add_button a").toggle(function(){
		
		$(this).css({"box-shadow":"rgba(0, 0, 0, 0.85) 0 1px 3px inset"});
		$(" #desktop_app_panel").fadeOut();
		$(" #desktop_add_app_panel").fadeIn();
		$(" #app_list_panel").transition({"height":"86%"},750);

	},function(){
		
		$(this).css({"box-shadow":"inset 0 0 1px white"});
		$(" #desktop_add_app_panel").fadeOut();
		//$(" #desktop_app_panel").fadeIn();
	
		$(" #app_list_panel").transition({"height":"0px"},500,function(){$(" #desktop_app_panel").fadeIn();});

	});

	
	UpdateAppList();

	//events:
	$('.COVER').live('click',function(e){
		if(e.target == this){
			$('.COVER').transition({
			'background':'rgba(0, 0, 0, 0.01)'
			},500);
			$(this).find('.card_div').transition({
				 scale: 0.01
			},500,function(){

				$('.COVER').remove();

			});
		}
		
		
	});

});

          